import java.util.Vector;
import java.io.BufferedReader;

class SymbolDictionary {
    class Item {
        int index;
        int heapAddress;
        String id;
        
        Item(int idx, int add, String identifier) {
            index = idx;
            heapAddress = add;
            id = identifier;
        }
        
        String asString() {
            return index + "\t" + heapAddress + "\t" + id;
        }
    }
    
    Vector<Item> items = new Vector<Item>();
    
    public SymbolDictionary(BufferedReader reader) throws Exception{
        reader.readLine();    //dictionary length header
        int numLines = Integer.parseInt(reader.readLine().trim());
        reader.readLine();    //dictionary length:
        for(int i = 0; i < numLines; i++) {
            String[] parts = reader.readLine().trim().split("[ \t]+");
            int index = Integer.parseInt(parts[0]);
            int heapAddress = Integer.parseInt(parts[1]);
            String id = parts[2];
            items.add(new Item(index, heapAddress, id));
        }
    }
    
    public int getHeapAddress(String symbol) throws Exception {
        for(Item i: items)
            if(i.id == symbol)
                return i.heapAddress;
        throw new Exception("Symbol not found.");
    }
    
    public String asString(String type) {
        String ret = type + " length:\n";
        ret = ret + items.size() + "\n";
        ret = ret + type + ":";
        for(Item i: items)
            ret = ret + "\n" + i.asString();
        return ret;
    }
    
    public void dump() {
        for(Item item: items)
            System.out.println(item.asString());
    }
}
